package com.hdw.job.batch.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.hdw.common.base.BaseException;
import com.hdw.job.batch.element.Column;
import com.hdw.job.batch.element.DateColumn;
import com.hdw.job.batch.element.LongColumn;
import com.hdw.job.batch.mapper.JDBCWriterRowMapper;
import com.hdw.med.bean.model.MdMedPubfld;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class DimStatus {
    private String columnName;
    //  -1无法分类的维度 1系统添加列 2度量  3名称   4无维度配置的字段 5有维度配置，但无维度表的字段
    private Integer columnType = -1;
    private String sdDimtp;

    @JsonIgnore
    private MdMedPubfld mdMedPubfld;
    private Integer nullCount = 0;
    private Integer addDimCount = 0;

    private Date paramDate = new Date();

    @JsonIgnore
    private Map<String, Map<String, Column>> unknownDim = new HashMap<>(0);

    public DimStatus(String columnName, Integer columnType, MdMedPubfld mdMedPubfld) {
        this.columnName = columnName;
        this.columnType = columnType;
        this.sdDimtp = mdMedPubfld.getSdDimtp();
        this.mdMedPubfld = mdMedPubfld;
    }

    public DimStatus(String columnName, Integer columnType) {
        this.columnName = columnName;
        this.columnType = columnType;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        this.columnName = columnName;
    }

    public Integer getColumnType() {
        return columnType;
    }

    public void setColumnType(Integer columnType) {
        this.columnType = columnType;
    }

    public MdMedPubfld getMdMedPubfld() {
        return mdMedPubfld;
    }

    public void setMdMedPubfld(MdMedPubfld mdMedPubfld) {
        this.sdDimtp = mdMedPubfld.getSdDimtp();
        this.mdMedPubfld = mdMedPubfld;
    }

    public Integer getNullCount() {
        return nullCount;
    }

    public void setNullCount(Integer nullCount) {
        this.nullCount = nullCount;
    }

    public Integer getAddDimCount() {
        return addDimCount;
    }

    public void setAddDimCount(Integer addDimCount) {
        this.addDimCount = addDimCount;
    }

    public Map<String, Map<String, Column>> getUnknownDim() {
        return unknownDim;
    }

    public void setUnknownDim(Map<String, Map<String, Column>> unknownDim) {
        this.unknownDim = unknownDim;
    }

    public void addUnknownDim(Column cd, Column na) throws BaseException {
        if (cd != null && cd.getRawData() != null) {
            Map<String, Column> oneDim = new HashMap<>();
            oneDim.put("CD", cd);
            oneDim.put("NA", na);
            oneDim.put(JDBCWriterRowMapper.ADD_COLUMN_EU_TP, new LongColumn(2));
            if (!StringUtils.isEmpty(StringUtils.trim(cd.asString()))) {
                this.unknownDim.put(StringUtils.trim(cd.asString()), oneDim);
            }
        }
    }

    public Integer getAddDimQuantity() {
        return unknownDim.size();
    }


    public String getSdDimtp() {
        return sdDimtp;
    }

    public void setSdDimtp(String sdDimtp) {
        this.sdDimtp = sdDimtp;
    }
}
